package com.zhenhao.xsq.ui.activity.camera;


import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import com.zhenhao.xsq.R;
import com.zhenhao.xsq.adapter.camera.CameraListAdapter;
import com.zhenhao.xsq.adapter.door.DoorManageAdapter;
import com.zhenhao.xsq.application.AppConfig;
import com.zhenhao.xsq.base.BaseActivity;
import com.zhenhao.xsq.ui.activity.camera.component.DaggerCameraListComponent;
import com.zhenhao.xsq.ui.activity.camera.contract.CameraListContract;
import com.zhenhao.xsq.ui.activity.camera.module.CameraListModule;
import com.zhenhao.xsq.ui.activity.camera.presenter.CameraListPresenter;
import com.zhenhao.xsq.utils.TimeUtil;
import com.zhenhao.xsq.utils.ToastUtil;
import com.zhenhao.xsq.utils.UIUtils;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author xlei
 * @Package com.yxld.gb.xsq.ui.activity.camera
 * @Description: $description
 * @date 2019/04/28 14:45:31
 */

public class CameraListActivity extends BaseActivity implements CameraListContract.View {

    @Inject
    CameraListPresenter mPresenter;
    @BindView(R.id.tv_devices_online)
    TextView tvDevicesOnline;
    @BindView(R.id.tv_devices_offline)
    TextView tvDevicesOffline;
    @BindView(R.id.rv)
    RecyclerView rv;
    @BindView(R.id.srl)
    SmartRefreshLayout srl;

    private CameraListAdapter adapter;

    @Override
    protected void initView() {
        setContentView(R.layout.activity_camera_list);
        ButterKnife.bind(this);
        //        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        autolayout.setBackgroundColor(ContextCompat.getColor(this, R.color.color_00000000));
        mToolbar.setBackgroundColor(ContextCompat.getColor(this, R.color.color_00000000));
        rootLayout.setBackground(ContextCompat.getDrawable(this, R.mipmap.bg_activity_base));
        toolbarTitle.setTextColor(ContextCompat.getColor(this, R.color.black));
        toolbarMenu.setTextColor(ContextCompat.getColor(this, R.color.color_333333));
        mToolbar.setNavigationIcon(ContextCompat.getDrawable(this, R.mipmap.toolbar_back2));

        setToolbarTitle("公共监控");

        initRv();

    }

    private void initRv() {
        UIUtils.configRecycleView(rv, new LinearLayoutManager(this));
        adapter = new CameraListAdapter();
        rv.setAdapter(adapter);

        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter baseQuickAdapter, View view, int i) {

            }
        });

        srl.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                srl.finishRefresh();
                srl.resetNoMoreData();

                initData();
            }
        });
    }

    @Override
    protected void initData() {

        List<String> list = new ArrayList<>();
        list.add("1");
        list.add("1");
        list.add("1");
        adapter.setNewData(list);
    }

    @Override
    protected void setupActivityComponent() {
        DaggerCameraListComponent
                .builder()
                .appComponent(((AppConfig) getApplication()).getApplicationComponent())
                .cameraListModule(new CameraListModule(this))
                .build()
                .inject(this);
    }

    @Override
    public void setPresenter(CameraListContract.CameraListContractPresenter presenter) {
        mPresenter = (CameraListPresenter) presenter;
    }

    @Override
    public void showProgressDialog() {
        progressDialog.show();
    }

    @Override
    public void closeProgressDialog() {
        progressDialog.hide();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}